
import re
import matplotlib.pyplot as plt
import numpy as np

FILE = 'build/path_output_gpu.txt'
# FILE = 'build/refline.txt'
# FILE = 'build/path_output_cpu.txt'

with open(FILE, 'r') as fd:
    data = fd.readlines()

def to_sl(sl_str):
    s, l = sl_str.split(',')
    return float(s), float(l)

fig, ax = plt.subplots()

max_s = -float('inf')
min_s = float('inf')
max_l = -float('inf')
min_l = float('inf')

print(f'data len: {len(data)}')
for line in data:
    result = re.findall(r'\((.*?)\)', line) 
    s_list = []
    l_list = []

    for point_index, sl_str in enumerate(result):
        s, l = to_sl(sl_str)
        s_list.append(s)
        l_list.append(l)

    max_s = max(max(s_list), max_s)
    max_l = max(max(l_list), max_l)
    min_s = min(min(s_list), min_s)
    min_l = min(min(l_list), min_l)
    # print(f's_list len: {len(s_list)}')

    ax.plot(s_list, l_list, linestyle='-', linewidth=0.1)

print(f'max_s: {max_s}, max_l: {max_l}, min_s: {min_s}, min_l: {min_l}')
ax.set_aspect(1.0)
ax.grid(True, which='both', linestyle='--', linewidth=0.5)
# ax.set_xticks(np.arange(min_s, max_s, 10.0))  # x轴刻度步长0.5
# ax.set_yticks(np.arange(min_l, max_l, 10.0))  # y轴刻度步长0.5
 
plt.show()